package sistema;

public abstract class Sistema {

	private int n;
	protected double[][] a;
	protected double[] y;

	public Sistema(double[][] a, double[] y) {
		if (a.length != y.length)
			throw new IllegalArgumentException("Sistema malformato");

		for (int i = 0; i < a.length; i++)
			if (a[i].length != a.length)
				throw new IllegalArgumentException("Sistema malformato");

		this.n = a.length;
		this.a = new double[n][n];
		this.y = new double[n];
		System.arraycopy(y, 0, this.y, 0, n);
		for (int i = 0; i < n; i++)
			System.arraycopy(a[i], 0, this.a[i], 0, n);

	}

	public int getN() {
		return n;
	}

	public String toString() {
		StringBuilder sb = new StringBuilder(200);
		for (int i = 0; i < getN(); i++) {
			for (int j = 0; j < getN(); j++) {
				sb.append(String.format("%1.2f ", a[i][j]));// notare lo spazio
															// dopo la f
			}
			sb.append('\n');
		}
		for (int i = 0; i < getN(); i++) {
			sb.append(String.format("1.2f\n", y[i]));

		}
		return sb.toString();
	}

	public abstract double[] risolvi();

}
